package com.example.controller;

import com.example.pojo.Event;
import com.example.pojo.EventDetailVO;
import com.example.pojo.Response;
import com.example.pojo.Spot;
import com.example.service.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/event")
public class EventController {
    @Autowired
    private EventService eventService;
    @GetMapping("/{id}")
    public Response<EventDetailVO> getEventDetail(@PathVariable Integer id) {
        EventDetailVO event = eventService.getEvent(id);
        if (event != null) {
            return Response.success(event);
        } else {
            return Response.fail("活动不存在");
        }
    }

    @GetMapping("/list")
    public Response<List<Event>> getEventsList(@RequestParam(required = false) Integer spotId) {
        List<Event> eventList = eventService.getEvents(spotId);
        if (eventList != null) {
            return Response.success(eventList);
        } else {
            return Response.fail("活动不存在");
        }
    }
}
